package cn.gxj62;

import java.util.ArrayList;

public class secelt {
    public static ArrayList<Student> getMaxAgeStudents(ArrayList<Student> list) {
        int maxAge = list.get(0).getAge();
        ArrayList<Student> maxAgeStudent = new ArrayList<>();
        for (Student s : list) {
            if (s.getAge() > maxAge) {
                maxAge = s.getAge();
            }
        }
        for (Student s : list) {
            if (s.getAge() == maxAge) {
                maxAgeStudent.add(s);
            }
        }
        return maxAgeStudent;
    }

    public static ArrayList<Student> getMinAgeStudents(ArrayList<Student> list) {
        int minAge = list.get(0).getAge();
        ArrayList<Student> minAgeStudent = new ArrayList<>();
        for (Student s : list) {
            if (s.getAge() < minAge) {
                minAge = s.getAge();
            }
        }
        for (Student s : list) {
            if (s.getAge() == minAge) {
                minAgeStudent.add(s);
            }
        }
        return minAgeStudent;
    }

    public static ArrayList<Student> getLeaderStudents(ArrayList<Student> list) {
        ArrayList<Student> leader = new ArrayList<>();
        for (Student s : list) {
            if (s.isLeader()) {
                leader.add(s);
            }
        }
        return leader;
    }

    public static int getMaleCount(ArrayList<Student> list) {
        int maleNum = 0;
        for (Student s : list) {
            if (s.getSex()) {
                maleNum++;
            }
        }
        return maleNum;
    }

    public static int getFemaleCount(ArrayList<Student> list) {
        int femaleNum = 0;
        for (Student s : list) {
            if (!s.getSex()) {
                femaleNum++;
            }
        }
        return femaleNum;
    }
}
